package com.tuyan.aixiang.component;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jaychan.view.MultipleTextView;
import com.tuyan.aixiang.R;
import com.tuyan.aixiang.common.lang.VoidFunction;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.ButterKnife;

public class DeviceListTitle extends LinearLayout {

    @BindView(R.id.ll_link_btn)
    LinearLayout llLinkBtn;

    @BindView(R.id.tv_title)
    TextView tvTitle;

    @BindView(R.id.mtv_count)
    MultipleTextView mtvCount;

    public DeviceListTitle(Context context) {
        this(context, null);
    }

    public DeviceListTitle(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public DeviceListTitle(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View contentView  = LayoutInflater.from(context).inflate(R.layout.device_list_title, this);
        ButterKnife.bind(contentView, this);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.DeviceListTitle);
        String title = ta.getString(R.styleable.DeviceListTitle_dlt_tt);
        tvTitle.setText(title);
        ta.recycle();
    }

    public void setCount(int count) {
        mtvCount.setContentText(count + "");
    }

    public void setLinkClick(VoidFunction function) {
        llLinkBtn.setOnClickListener(v -> function.call());
    }

}
